package com.baway.biliclitent.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baway.biliclitent.R;
import com.baway.biliclitent.model.DesBean;
import com.bumptech.glide.Glide;

import java.util.List;


/**
 * Created by dell on 2017/3/23.
 */

public class SynopsisFragment_Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<DesBean.DataBeanHeadline.RelatesBeanHeadline> relates;
    private Context context;

    public SynopsisFragment_Adapter(List<DesBean.DataBeanHeadline.RelatesBeanHeadline> relates, Context context) {
        this.relates = relates;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.region_recomm_lv,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((ViewHolder)holder).item_title.setText(relates.get(position).getTitle());
        ((ViewHolder)holder).item_user_name.setText(relates.get(position).getOwner().getName());
        ((ViewHolder)holder).item_play.setText(relates.get(position).getStat().getView()+"");
        ((ViewHolder)holder).item_review.setText(relates.get(position).getStat().getReply()+"");

        Glide.with(context)
                .load(relates.get(position).getPic())
                .into(((ViewHolder)holder).item_img);

    }

    @Override
    public int getItemCount() {
        return relates.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder{
        TextView item_title,item_user_name,item_play,item_review;
        ImageView item_img;

        public ViewHolder(View itemView) {
            super(itemView);
            item_title = (TextView) itemView.findViewById(R.id.item_title);
            item_user_name = (TextView) itemView.findViewById(R.id.item_user_name);
            item_play = (TextView) itemView.findViewById(R.id.item_play);
            item_review = (TextView) itemView.findViewById(R.id.item_review);
            item_img = (ImageView) itemView.findViewById(R.id.item_img);
        }
    }
}
